﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExampleImplementation;

namespace LoRel.Example
{
    public class Example
    {
        public void DoExample()
        {
            // SELECT Pos.Trader, Pos.Symbol, MD.Price
            // FROM Pos JOIN MD 
            //  ON Pos.Symbol = MD.Symbol

            Expression pos_symbol_key = CORE.Exp.Register( 
                                                    text: "Pos.Symbol", 
                                                    eval: delegate(object input)
                                                       {
                                                           Pos p = (Pos)input;
                                                           return new SymbolKey(p.Symbol);
                                                       }
                                        );

            Expression md_symbol_key = CORE.Exp.Register( 
                                                        text: "MD.Symbol", 
                                                        eval: delegate(object input)
                                                          {
                                                              MD md = (MD) input;
                                                              return new SymbolKey(md.Symbol);
                                                          });

            // the join is how we connect the subscriptions and initialize
            LeftJoin join = new LeftJoin( "PosMDJoin", pos_symbol_key, md_symbol_key );



            // type registration
            CORE.Exp.Register(pos_symbol_key);
            CORE.Exp.Register(md_symbol_key);

            CORE.Data.Register( "PosMDJoin", join );


            // runtime initialization
            IProvider md_provider = CORE.Data.GetProvider( md_symbol_key );
            IProvider pos_provider = CORE.Data.GetProvider( pos_symbol_key );

            join.Register( pos_provider, md_provider );


        }
    }
}
